<?php

session_start();

/**
 * @author Janosch Hirth
 * @copyright 2013
 */

include 'nav.inc.php';
include 'dbConn.php';

html_head_without_openings('Aufgabenmanager - Alle Aufgaben auf einen Blick');


	if(!isset($_SESSION["username"]))
	{					//kontrolliere ob Benutzer eingelogt ist
		echo("\n<div class='content' style='margin-left:400px'>");
	   echo ("\n\t\tBitte erst <a href='../login.php'>einloggen</a>.");
	}
	else{									//Kosmetik der Seite
		menu();
		echo("\n<div class='content' style='margin-left:400px'>");
		echo "\n\t<table style='table-layout:fixed;' rules='cols' border='0'>";
		echo "\n\t\t<tr>";
		echo "\n\t\t\t<th colspan='1', style='background:#ffe4b5'>";
		echo "\n\t\t\t\tAufgabe";
		echo "\n\t\t\t</th>";
		echo "\n\t\t\t<th colspan='1', style='background:#ffe4b5'>";
		echo "\n\t\t\t\tEingestellt";
		echo "\n\t\t\t</th>";
		echo "\n\t\t\t<th colspan='1', style='background:#ffe4b5'>";
		echo "\n\t\t\t\tDeadline";
		echo "\n\t\t\t</th>";
		echo "\n\t\t\t<th colspan='1', style='background:#ffe4b5'>";
		echo "\n\t\t\t\tGedacht für";
		echo "\n\t\t\t</th>";
		echo "\n\t\t\t<th colspan='1', style='background:#ffe4b5'>";
		echo "\n\t\t\t\tAktiv für (seit)";
		echo "\n\t\t\t</th>";
		echo "\n\t\t\t<th colspan='1', style='background:#ffe4b5'>";
		echo "\n\t\t\t\tPriorität";
		echo "\n\t\t\t</th>";
		echo "\n\t\t</tr>";
		$query = "SELECT * From task_Aufgaben ORDER BY DEADLINE ASC";
		$result = mysql_query($query) or die (mysql_error());
		while ($row = mysql_fetch_array($result)) 
		{
			echo "\n\t\t<tr>";
			echo "\n\t\t\t<td colspan='1', style='background:#ffffe0'>";
			echo "\n\t\t\t\t".$row['Titel'];
			echo "\n\t\t\t</td>";
			echo "\n\t\t\t<td colspan='1', style='background:#faf0e6'>";
			echo "\n\t\t\t\t".$row['EingestelltAm'];
			echo "\n\t\t\t</td>";
			echo "\n\t\t\t<td colspan='1', style='background:#ffffe0'>";
			echo "\n\t\t\t\t".$row['Deadline'];
			echo "\n\t\t\t</td>";
			echo "\n\t\t\t<td colspan='1', style='background:#faf0e6'>";
			$query = "SELECT m_vname, m_name 
						FROM task_istGedachtFor 
							JOIN std_mitarbeiter 
								ON NID=m_id 
						WHERE AID ='".$row['AID']."'";	
			$result2 = mysql_query($query) or die (mysql_error());
			$first = 1;
			while ($row2 = mysql_fetch_array($result2)) 
			{
					if (!$first)
						echo ", ";
					echo "\n\t\t\t\t".$row2['m_vname']." ".$row2['m_name'];
					if($first) $first = 0;
			}
			$query = "SELECT m_vname, m_name, Startdatum 
						FROM task_wirdBearbeitetVon 
							JOIN std_mitarbeiter 
								ON NID=m_id 
						WHERE AID ='".$row['AID']."'";	
			$result2 = mysql_query($query) or die (mysql_error());
			$first = 1;
			echo "\n\t\t\t</td>";
			echo "\n\t\t\t<td>";
			while ($row2 = mysql_fetch_array($result2)) 
			{
					if (!$first)
						echo "\n\t\t\t<colspan='1', style='background:#ffffe0'>";
						echo " ";
					echo "\n\t\t\t\t".$row2['m_vname']." ".$row2['m_name']." (".$row2['Startdatum'].")</br>";
					if($first) $first = 0;
			}
			echo "\n\t\t\t</td>";
			if ($first)
			{
				echo "\n\t\t\t<td colspan='1', style='color:red'>";
				if ($first) echo " NIEMANDEN?!? ";
				echo "\n\t\t\t</td>";
			}
			echo "\n\t\t\t<td colspan='1', style='background:#faf0e6;text-align:center;'>";
			echo "\n\t\t\t\t".$row['Priorität'];
			echo "\n\t\t\t</td>";
			echo "\n\t\t</tr>";
		}
		echo "\n\t</table>";
	}
	echo("\n</div>");
?>
